# Pre-definition.
CPP := g++
AR_RCU := ar rcu
AR_XV := ar xv
RANLIB := ranlib

DEPS := ../deps
V8_PATH := $(DEPS)/v8
V8_INC := $(V8_PATH)/include
V8_LIB := $(V8_PATH)
CO_PATH := $(DEPS)/pcl
CO_INC := $(CO_PATH)/include
CO_LIB := $(CO_PATH)/pcl/.libs/libpcl.a
CFLAGS := -I$(V8_INC) -I$(CO_INC) -fno-rtti -fno-exceptions -O2
LIBS := -L$(V8_LIB) -lv8 -L$(CO_LIB) -lpcl -lpthread
LIB_OPTION := -Wall

# Coroutine artefects.
COR_BUILD := libjscoro.a
COR_OBJS := coroutine.o
COR_BINS := $(COR_OBJS) $(COR_BUILD)

all: $(COR_BUILD)

%.o: %.cc
	$(CPP) -c $(CFLAGS) -o $@ $<

$(COR_BUILD): $(COR_OBJS)
	$(AR_XV) $(CO_LIB)
	$(AR_RCU) $@ *.o
	$(RANLIB) $@

withv8: $(COR_OBJS)
	$(AR_XV) $(CO_LIB)
	$(AR_XV) $(V8_LIB)/libv8.a
	$(AR_RCU) $(COR_BUILD) *.o
	$(RANLIB) $(COR_BUILD)

test: all
	./shell --shell test.js

clean:
	rm -rf $(COR_BINS)
	rm *.o
